trigger OORUpdateAFAssignedOrder on Account (after Update) {

    //Trigger Name: OORUpdateAFAssignedOrder  
    //Author: Accenture IDC   
    //Project Name: OOR Phase 2    
    //Purpose: For Removing Secondary owner from Opportunity When Account's Secondary Owner is NULL.  
    //Date: 30/01/2012
    
     Set<Id> AccountSet = New Set<Id>();//Set for Storing Unique Account Ids 
     Map<Id,Id> AcctMap= New Map<Id,Id>();//Map for Storing Key Value Pair
     ID SFAOORAccountecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
     for (Account acct:Trigger.New){
              if(acct.RecordTypeId==SFAOORAccountecordTypeID && acct.OOR_Secondary_Account_Owner__c==NULL && Trigger.OldMap.get(acct.id).OOR_Secondary_Account_Owner__c!=NULL  && acct.OOR_Secondary_Account_Owner__c!=Trigger.OldMap.get(acct.id).OOR_Secondary_Account_Owner__c && acct.Recurring_Charge__c!=NULL){
                 AccountSet.add(acct.Id);
                 AcctMap.put(acct.Id,acct.OOR_Secondary_Account_Owner__c);//Key: Account Id and Value:Account's Secondary Owner
            }
        }
     if(AccountSet.Size()>0){
        List<Opportunity> UpdateOrder=[Select Id,AccountID,Secondary_Owner__c,Account.Secondary_Owner__c from Opportunity where AccountId IN:AccountSet];//List Retrieving the List of Opportunities Tied to this Particular AccountId
          for(Opportunity oppty:UpdateOrder){
               //Check if Secondary Owner on Opportunity is NOT NULL
                if(oppty.Secondary_Owner__c!=NULL){
                    oppty.Secondary_Owner__c=AcctMap.get(Oppty.AccountID);//Update NULL
                       }}
               if(UpdateOrder.Size()>0){
                 Try{
                    Update UpdateOrder;//Update all the Opportunities to Reflect Secondary Owner as NULL.
                    }Catch(DMLException exe){
                      GeneralConstants.mailAnyExceptionToMe('OORUpdateAFAssignedOrder','Trigger on Account',exe); //Notify Catched Exception (If any) to Salesforce DEV Team                   
                   } 
            }
      } 
  }